package cn.middle.edge.portal;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.middle.common.result.Page;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.middle.edge.entity.Event;
import cn.middle.edge.service.EventService;

@Controller
@RequestMapping("/event")
public class EventController {
	
	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	private final static String PREFIX = "edge/event/";
	
	@Autowired
	private EventService eventService;
	
	@SaCheckPermission("event:list")
	@GetMapping("/list")
	public String list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
			@RequestParam(value = "limit", defaultValue = "10") Integer limit, String serviceId, Integer eventCode,
			 String keyword, ModelMap modelMap) {
		logger.info("queryParam  serviceId={}, eventCode={}, keyword={}",serviceId,eventCode,keyword);
		Page<Event> events = this.eventService.listConditions(pageNum, limit, serviceId, eventCode, keyword);
		modelMap.put("serviceId", serviceId);
		modelMap.put("eventCode", eventCode);
		modelMap.put("keyword", keyword);
		modelMap.put("pageInfo", events);
		return PREFIX + "list";
	}

}
